#! /usr/bin/env python3
# -*- coding=utf8 -*-


from pymysql import *

conn = connect(host='localhost', port=3306, database='jing_dong', user='root', password='root', charset='utf8',
               ssl=False)


def main():
    # 创建Connection连接
    conn = connect(host='localhost', port=3306, database='jing_dong', user='root', password='root', charset='utf8',
                   ssl=False)
    # 获取cursor
    cursor = conn.cursor()
    # sql
    sql = r'select `id`, `name`, `cate_id`, `brand_id`, `price`, `is_show` from goods where id =1'
    rowcount = cursor.execute(sql)
    print(rowcount)
    fetchall = cursor.fetchone()
    print(fetchall)
    for i in range(len(fetchall)):
            print(fetchall[i])

    # 提交之前的操作，如果之前已经之执行过多次的execute，那么就都进行提交
    conn.commit()
    # 关闭Cursor对象
    cursor.close()
    # 关闭Connection对象
    conn.close()


if __name__ == '__main__':
    main()
